package com.aotuman.ktcoroutineandroid.chapter.javademo;

import kotlin.coroutines.Continuation;
import kotlin.coroutines.intrinsics.IntrinsicsKt;

public class SuspendFunctions {

    public static final Object COROUTINE_SUSPENDED = IntrinsicsKt.getCOROUTINE_SUSPENDED();

    public static Object returnSuspended(Continuation continuation){
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                continuation.resumeWith("Return suspended.");
            }
        }).start();

        return COROUTINE_SUSPENDED;
    }

    public static Object returnImmediately1(Continuation continuation){
        return "Return Immediately1. ";
    }

    public static Object returnImmediately2(Continuation continuation){
        return "Return Immediately2. ";
    }
}

